﻿using DateGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace DateGeneratorTests
{
    [TestClass]
    public class DateGeneratorLowerLimitsTest
    {
        private RandomDate _sut;
        private DateTime _pastLowerBoundary;
        private DateTime _pastUpperBoundary;

        private DateTime _futureUpperBoundary;
        private DateTime _futureLowerBoundary;

        [TestInitialize]
        public void TestSetUp()
        {
            var randomStub = new System.Fakes.StubRandom

            {
                NextInt32Int32 = (i, i1) => i
            };            

            _sut = new RandomDate(randomStub);

            _pastLowerBoundary = new DateTime(2010, 04, 22);
            _pastUpperBoundary = new DateTime(2010, 05, 01);

            _futureUpperBoundary = new DateTime(2020, 12, 30);
            _futureLowerBoundary = new DateTime(2020, 12, 20);
        }

        [TestMethod]
        public void Test_LowerBoundary_DateGenerator_Future_Method()
        {

            DateTime generatedDate = _sut.Future();

            //Ensure the generated date is in the future
            Assert.IsTrue(generatedDate > DateTime.Today, "The generated date {0} is not in the past", generatedDate.ToShortDateString());
        }

        [TestMethod]
        public void Test_LowerBoundary_DateGenerator_Past_Boundaries()
        {
            //Define range of desired dates in the past
            //Our generator will create dates within these boundaries
            _sut.LowerBoundary = _pastLowerBoundary;
            _sut.UpperBoundary = _pastUpperBoundary;

            //Generates a date in the past, after LowerBoundary but before UpperBoundary
            //Since this time we are using a stub for the random object, the date generated should be 1 daqy before the upper boundary
            DateTime generatedDate = _sut.Generate();

            //Assert date is in the past
            Assert.IsTrue(DateTime.Today > generatedDate);
            //Assert dates are within specified range
            Assert.IsTrue(_pastLowerBoundary < generatedDate, "Generated date 1 is outside the lower boundary range. Generated Date: {0} Lower Boundary {1}", generatedDate, _pastLowerBoundary);
            Assert.IsTrue(_pastUpperBoundary > generatedDate, "Generated date 1 is outside the upper boundary range. Generated Date: {0} Upper Boundary: {1}", generatedDate, _pastUpperBoundary);
        }

        [TestMethod]
        public void Test_LowerBoundary_DateGenerator_Future_Boundaries()
        {
            _sut.LowerBoundary = _futureLowerBoundary;
            _sut.UpperBoundary = _futureUpperBoundary;

            //Generates a date in the past, after LowerBoundary but before UpperBoundary
            //Since this time we are using a stub for the random object, the date generated should be 1 daqy before the upper boundary
            DateTime generatedDate = _sut.Generate();

            //Assert date is in the past
            Assert.IsTrue(DateTime.Today < generatedDate);
            //Assert dates are within specified range
            Assert.IsTrue(_futureLowerBoundary < generatedDate, "Generated date 1 is outside the lower boundary range. Generated Date: {0} Lower Boundary {1}", generatedDate, _pastLowerBoundary);
            Assert.IsTrue(_futureUpperBoundary > generatedDate, "Generated date 1 is outside the upper boundary range. Generated Date: {0} Upper Boundary: {1}", generatedDate, _pastUpperBoundary);
        }
    }
}
